package com.wnxy.d_syn;

import java.util.concurrent.locks.ReentrantLock;

/**
 * ReentrantLock 可重入锁
 * 1、Lock锁比synchronize灵活，自己调用方法获取锁、释放锁
 *   lock.lock();    获取锁
 *   lock.unlock();  释放锁
 */
public class ReentrantLockApp {
    public static void main(String[] args) {
        ReentrantLock lock = new ReentrantLock();
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    lock.lock();
                    System.out.println("进入锁");
                    lock.lock();
                    System.out.println("再次进入锁，说明锁可重入的特性！");
                } finally {
                    lock.lock(); // 释放锁
                }
            }
        }).start();
    }
}
